package michaelgame.sprite;

import java.awt.Dimension;
import java.awt.Point;
import michaelgame.Constants;
import framework.Level;
import framework.Sprite;


/**
 * 
 * @author Michael Deng
 * 
 */
public class Player extends Sprite {

    private final String myImageFile = "player.jpg";
    private final int myWidth = 93;
    private final int myHeight = 145;
    private final int myVelocity = 7;

    @Override
    public void initialize (Point position, Level l) {
        Dimension bounds = Constants.SIZE;
        Point newPosition = new Point(bounds.width / 2, bounds.height - myHeight / 2 + 1);
        super.superInitialize(newPosition, myImageFile, myWidth, myHeight, l);
    }

    @Override
    protected void move () {
        String key = getMyLevel().getMyGame().getMyContainer().getLastKeyPressed();
        Dimension bounds = Constants.SIZE;

        if (key.equalsIgnoreCase("a")) {
            getMyCenter().translate(-myVelocity, 0);
            if (getLeft() < 0) {
                getMyCenter().translate(myVelocity, 0);
            }
        }
        else if (key.equalsIgnoreCase("d")) {
            getMyCenter().translate(myVelocity, 0);
            if (getRight() > bounds.width) {
                getMyCenter().translate(-myVelocity, 0);
            }
        }
        else if (key.equalsIgnoreCase("w")) {
            getMyCenter().translate(0, -myVelocity);
            if (getTop() < 0) {
                getMyCenter().translate(0, myVelocity);
            }
        }
        else if (key.equalsIgnoreCase("s")) {
            getMyCenter().translate(0, myVelocity);
            if (getBottom() > bounds.height) {
                getMyCenter().translate(0, -myVelocity);
            }
        }
    }

    @Override
    protected void action () {
        // no actions
    }
}
